New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

township-client

Package Overview
Dependencies
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

township-client

Township auth client library

  • 1.3.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
57
decreased by-17.39%
Maintainers
4
Weekly downloads
 
Created
Source

Township Auth Client Module

Travis npm

Client library to login, register, and change passwords for users using township auth server(s).

Features
  • Manage user credentials for many Township servers.
  • Login, Register, and Change Password auth requests.
  • Login information is persisted to a configuration file.

Usage

var TownshipClient = require('township-client')
var client = TownshipClient({
  server: 'https://api.township.site' // Set default server on init
  config: {
    filename: '.townshiprc' 
    // config file stored in user homedir. 
    // uses localstorage if in browser
  }
})

client.register({
  email: 'joe@hand.email',
  password: 'Iheartcoffee'
}, function (err, res, body) {
  if (err) return console.error('Register error', err)
  console.log('Registered successfully with ', body.key, body.token)
})

client.login({
  email: 'joe@hand.email',
  password: 'Iheartcoffee'
}, function (err, res, body) {
  if (err) return console.error('Login error', err)
  console.log('Logged in successfully!')
})

API

var township = Township(opts)

Options include:

opts = {
  server: 'https://api.township.com',// Township API server
  config: {
    filename: '.townshiprc', // configuration filename (stored in os homedir)
    filepath: '~/.townshiprc' // specify a full config file path 
  },
  routes: { // routes for ALL township servers used by client
    register: '/register',
    login: '/login',
    updatePassword: '/updatepassword'
  }
}

opts.server can be set once on initialization or during each request. The client can handle multiple servers. opts.server can be passed with each request if the request should go to a different server than the client was initialized with.

Auth Requests

township.register(opts, cb)

Register a user and receive a token. opts.email and opts.password required.

township.login(opts, cb)

Login a registered user. opts.email and opts.password required

township.logout(opts, cb)

Logout from a server. Will logout of current server or opts.server, if provided.

township.changePassword(opts, cb)

Reset password for a registered user. opts.email, opts.password, and opts.newPassword required. User must have a valid login token saved before changing password.

township.secureRequest(opts, cb)

Make a secure request to the server. opts are passed to the request function. The opts should include opts.method and opts.url.

opts.url will be prefixed by the auth server if not already.

township.getLogin([server])

Get login information for a server. If no server is specified, returns current login info (from the most recent login or register action).

License

MIT

FAQs

Package last updated on 25 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc